﻿using Emgu.CV.CvEnum;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OpenCvApplication.View.CommonView
{
    public partial class BilateralFilterParameterControl : UserControl
    {
        public BilateralFilterParameterControl()
        {
            InitializeComponent();

            foreach (Control item in this.Controls)
            {
                if (item is TrackBar trackBar)
                    trackBar.Scroll += trackBar_Scroll;
            }
        }
        private void trackBar_Scroll(object sender, EventArgs e)
        {
            RefreshShow();
            ValueChange?.Invoke(this, Args);
        }
        public Action<object, BilateralFilterEventArgs> ValueChange { get; set; }
        private void BilateralFilterParameterControl_Load(object sender, EventArgs e)
        {
            ValueChange?.Invoke(this, Args);
        }
        private void RefreshShow()
        {
            label4.Text = NeighborhoodDiameter.ToString();
            label5.Text = ColorSpaceFilter.ToString("0.00");
            label6.Text = CoordinateSpaceFilter.ToString("0.00");
        }
        public int NeighborhoodDiameter => trackBar1.Value;
        public double ColorSpaceFilter => this.trackBar2.Value + (double)numericUpDown2.Value;
        public double CoordinateSpaceFilter=> this.trackBar3.Value + (double)numericUpDown1.Value;
        public BilateralFilterEventArgs Args => new BilateralFilterEventArgs(NeighborhoodDiameter, ColorSpaceFilter, CoordinateSpaceFilter);
    }
    public class BilateralFilterEventArgs : EventArgs
    {
        public BilateralFilterEventArgs()
        {
        }
        public BilateralFilterEventArgs(int nd, double csf, double cdsf) : this()
        {
            this.NeighborhoodDiameter = nd;
            this.ColorSpaceFilter = csf;
            this.CoordinateSpaceFilter = cdsf;
        }
        public int NeighborhoodDiameter { get; set; }
        public double ColorSpaceFilter { get; set; }
        public double CoordinateSpaceFilter { get; set; }
    }
}
